﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace WindowsFormsApplicationGDI4._2
{    
    public enum DrawMode { Pen, Line };

    public partial class Form1 : Form
    {
        private bool Drawing = false;
        public Form1()
        {
            InitializeComponent();
            button1.BackColor = Color.Silver;
        }

        private void Form1_MouseDown(object sender, MouseEventArgs e)
        {
            if (mode == DrawMode.Line)
            {
                if (line.IsEmpty)
                {
                    line = new Point(e.X, e.Y);
                }
                else
                {
                    Graphics gr = CreateGraphics();
                    gr.DrawLine(new Pen(button1.BackColor, trackBar1.Value), line, new Point(e.X, e.Y));
                    line = new Point();
                }
            }
            Drawing = true;
        }

        private void Form1_MouseUp(object sender, MouseEventArgs e)
        {
            Drawing = false;
            tmp = new Point();
        }
        
        Point tmp;
        Point line;
        DrawMode mode = DrawMode.Pen;

        private void Form1_MouseMove(object sender, MouseEventArgs e)
        {
            if (Drawing == true)
            {
                
                switch (mode)
                {
                    case DrawMode.Pen:
                        if (tmp.IsEmpty)
                        {
                            tmp = new Point(e.X, e.Y);
                        }

                        Point p = new Point(e.X, e.Y);
                        Graphics gr = CreateGraphics();
                        gr.DrawLine(new Pen(button1.BackColor, trackBar1.Value), tmp, new Point(e.X, e.Y));
                        tmp.X = e.X;
                        tmp.Y = e.Y;
                        break;
                    case DrawMode.Line:

                        break;
                }
                
                //gr.FillRectangle(new SolidBrush(button1.BackColor), new Rectangle(p, new Size(trackBar1.Value, trackBar1.Value)));
                //gr.DrawRectangle(new Pen(Color.OrangeRed, 10), new Rectangle(p, new Size(1, 1)));
            }
            else return;
        }

        private void button1_Click(object sender, EventArgs e)
        {
            ColorDialog cd = new ColorDialog();

            if (cd.ShowDialog() == DialogResult.OK)
            {
                (sender as Button).BackColor = cd.Color;
            }
        }

        private void button2_Click(object sender, EventArgs e)
        {
            mode = DrawMode.Line;
        }
    }
}

/*
 * прямоугольник и элипс
 * ломанная линия (curve)
*/